<?php
require_once ('mysql/mysqlresult.inc.php'); 
class mysql {
	private $link_identifier;

	public function __construct () {
	}

	//string mysql_client_encoding ([ resource $link_identifier ] )
	public function client_encoding () {
		return mysql_client_encoding ($this->link_identifier);
	}

	//bool mysql_close ([ resource $link_identifier ] )
	public function close () {
		return mysql_close ($this->link_identifier);
	}

	//resource mysql_connect ([ string $server [, string $username [, string $password [, bool $new_link [, int $client_flags ]]]]] )
	public function connect ($server = null, $username  = null, $password  = null, $new_link  = null, $client_flags = null) {
		$this->link_identifier = mysql_connect  ($server, $username, $password, $new_link, $client_flags);
		$this->checkerror ();
		return $this->link_identifier;
	}

	//bool mysql_create_db ( string $database name [, resource $link_identifier ] )
	public function create_db ($database) {
		return mysql_create_db ($database, $this->link_identifier);
	}

	//resource mysql_db_query ( string $database , string $query [, resource $ link_identifier ] )
	public function db_query ($database, $query) {
		return mysql_db_query ($database, $query, $this->link_identifier);
	}

	//bool mysql_drop_db ( string $database_name [, resource $ link_identifier ] )
	public function drop_db ($database_name) {
		return mysql_drop_db ($database_name, $this->link_identifier);
	}

	//int mysql_errno ([ resource $link_identifier ] )
	public function errno () {
		if ($this->link_identifier != null) {
			return mysql_errno ($this->link_identifier);
		} else {
			return mysql_errno ();
		}
	}

	//string mysql_error ([ resource $link_identifier ] )
	public function error () {
		if ($this->link_identifier != null) {
			return mysql_error ($this->link_identifier);
		} else {
			return mysql_error ();
		}
	}

	private function checkerror () {
		if ($this->errno () != 0) {
#			die ($this->error ());
			throw new Exception ($this->error ());
#			trigger_error ($this->error (), E_USER_ERROR);
		}
	}

	//string mysql_escape_string ( string $unescaped_string )
	public function escape_string ($unescaped_string) {
		return mysql_real_escape_string ($unescaped_string);
		//return mysql_escape_string ($unescaped_string);
	}

	//string mysql_get_client_info ( void )
	public function get_client_info () {
		return mysql_get_client_info ();
	}

	//string mysql_get_host_info ([ resource $link_identifier ] )
	public function get_host_info () {
		return mysql_get_host_info ($this->link_identifier);
	}

	//int mysql_get_proto_info ([ resource $link_identifier ] )
	public function get_proto_info () {
		return mysql_get_proto_info ($this->link_identifier);
	}

	//string mysql_get_server_info ([ resource $link_identifier ] )
	public function get_server_info () {
		return mysql_get_server_info ($this->link_identifier);
	}

	//string mysql_info ([ resource $link_identifier ] )
	public function info () {
		return mysql_info ($this->link_identifier);
	}

	//int mysql_insert_id ([ resource $link_identifier ] )
	public function insert_id () {
		return mysql_insert_id ($this->link_identifier);
	}

	//resource mysql_list_dbs ([ resource $link_identifier ] )
	public function list_dbs () {
		return mysql_list_dbs ($this->link_identifier);
	}

	//resource mysql_list_fields ( string $database_name , string $table_name [, resource $link_identifier ] )
	public function list_fields ($database_name, $table_name) {
		return mysql_list_fields ($database_name, $table_name, $this->link_identifier);
	}

	//resource mysql_list_processes ([ resource $link_identifier ] )
	public function list_processes () {
		return mysql_list_processes ($this->link_identifier);
	}

	//resource mysql_list_tables ( string $database [, resource $link_identifier ] )
	public function list_tables ($database) {
		return mysql_list_tables ($database, $this->link_identifier);
	}

	//resource mysql_pconnect ([ string $server [, string $username [, string $password [, int $client_flags ]]]] )
	public function pconnect ($server = null, $username = null, $password = null, $client_flags = null) {
		return mysql_pconnect ($server, $username, $password, $client_flags);
	}

	//bool mysql_ping ([ resource $ link_identifier ] )
	public function ping () {
		return mysql_ping ($this->link_identifier);
	}

	//resource mysql_query ( string $query [, resource $link_identifier ] )
	public function query ($query) {
		$resource = mysql_query ($query, $this->link_identifier);
		$this->checkerror ();
		return new mysqlresult ($this->link_identifier, $resource);
	}

	//string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )
	public function real_escape_string ($unescaped_string) {
		return mysql_real_escape_string ($unescaped_string, $this->link_identifier);
	}

	//bool mysql_select_db ( string $database_name [, resource $ link_identifier ] )
	public function select_db ($database_name) {
		$bool = mysql_select_db ($database_name, $this->link_identifier);
		$this->checkerror ();
		return $bool;
	}

	//bool mysql_set_charset ( string $charset [, resource $link_identifier = NULL ] )
	public function set_charset ($charset) {
		return mysql_set_charset ($charset, $this->link_identifier);
	}

	//string mysql_stat ([ resource $link_identifier ] )
	public function stat () {
		return mysql_stat ($this->link_identifier);
	}
	//int mysql_thread_id ([ resource $link_identifier ] )
	public function thread_id () {
		return mysql_thread_id ($this->link_identifier);
	}

	//resource mysql_unbuffered_query ( string $query [, resource $link_identifier ] )
	public function unbuffered_query ($query) {
		return mysql_unbuffered_query ($query, $this->link_identifier);
	}

}
?>